package biblioteca;

import java.util.Comparator;

public class ComparadorMaisVotado implements Comparator<Item> {
	
	private final double EPS = 1e-8;
	
	private final int BEFORE = -1,
						AFTER = 1,
						EQUALS = 0;
	
	private int compareDouble(double a, double b) {
		if(a - b > EPS)
			return BEFORE;
		else if(b - a > EPS)
			return AFTER;
		return EQUALS;
	}
	
	@Override
	public int compare(Item primeiroItem, Item segundoItem) {
		return compareDouble(primeiroItem.calculaMedia(), segundoItem.calculaMedia());
	}

}
